package com.tedu.ourprojct.controller;

import com.tedu.ourprojct.mapper.FoodPackageMapper;
import com.tedu.ourprojct.pojo.dto.FoodPackageDto;
import com.tedu.ourprojct.pojo.dto.FoodPackageUpdateDto;
import com.tedu.ourprojct.pojo.entity.FoodPackage;
import com.tedu.ourprojct.pojo.vo.FoodPackageAdminVO;
import com.tedu.ourprojct.pojo.vo.FoodPackageUpdateVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 套餐信息处理类
 * @author 袁田
 */
@RestController
@RequestMapping("/foodPackage")
public class FoodPackageController {
    @Autowired(required = false)
    FoodPackageMapper mapper;


    @RequestMapping("/select")
    public List<FoodPackageAdminVO> select(){
        return mapper.selectAdmin();
    }


    @RequestMapping("/insert")
    public void insert(@RequestBody FoodPackageDto foodPackage){
        System.out.println(foodPackage);
        FoodPackage fp=new FoodPackage();
        BeanUtils.copyProperties(foodPackage,fp);
        fp.setCreated(new Date());
        System.out.println(fp);
        mapper.insert(fp);
    }


    @RequestMapping("/selectUpdate")
    public FoodPackageUpdateVO selectUpdate(int id){
        return mapper.selectUpdate(id);
    }

    @RequestMapping("/delete")
    public void delete(int id){
        mapper.deleteById(id);
    }

    @RequestMapping("/update")
    public void update(@RequestBody FoodPackageUpdateDto foodPackage) {
        mapper.update(foodPackage);
    }





}
